package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.cert.dto.cert.ContractRewriteDTO;
import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.dto.OpenContractSyncDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 * @description
 */
public class ContractAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {

        @Mappings({
                @Mapping(source = "contractId", target = "id"),
                @Mapping(source = "tenantId", target = "createTenantId"),
                @Mapping(source = "content", target = "body"),
                @Mapping(source = "type", target = "twoType"),

                @Mapping(source = "first.tenantId", target = "tenantIdOne"),
                @Mapping(source = "first.name", target = "tenantNameOne"),
                @Mapping(source = "first.contactName", target = "userNameOne"),
                @Mapping(source = "first.address", target = "addressOne"),
                @Mapping(source = "first.contactMobile", target = "mobileOne"),
                @Mapping(source = "first.signDate", target = "signDateOne"),
                @Mapping(source = "first.confirm", target = "userIdOne"),
                @Mapping(source = "first.confirmTime", target = "confirmTimeOne"),

                @Mapping(source = "second.tenantId", target = "tenantIdTwo"),
                @Mapping(source = "second.name", target = "tenantNameTwo"),
                @Mapping(source = "second.contactName", target = "userNameTwo"),
                @Mapping(source = "second.address", target = "addressTwo"),
                @Mapping(source = "second.contactMobile", target = "mobileTwo"),
                @Mapping(source = "second.signDate", target = "signDateTwo"),
                @Mapping(source = "second.confirm", target = "userIdTwo"),
                @Mapping(source = "second.confirmTime", target = "confirmTimeTwo"),

                @Mapping(source = "attachments", target = "contractAttachments"),
        })
        ContractRewriteDTO assemble(OpenContractSyncDTO source);

    }

    public static ContractRewriteDTO assemble(OpenContractSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }
}
